package com.lufei.dh.ExList;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.lufei.dh.ExList.Adapter.Adapter_ExList;
import com.lufei.dh.ExList.Bean.Level0Item;
import com.lufei.dh.ExList.Bean.Level1Item;
import com.lufei.dh.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 版权：易金卡沃 版权所有
 * <p>
 * 作者：lufei
 * <p>
 * 创建日期：2018/6/9
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
public class ExListActivity extends AppCompatActivity {
    @BindView(R.id.id_exlist_recyclerview)
    RecyclerView idExlistRecyclerview;
    Adapter_ExList adapterExList;
    private List<MultiItemEntity> list=new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exlist);
        ButterKnife.bind(this);
        init();
        setList();
        setAdapterExList();
    }

    private void init() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        idExlistRecyclerview.setLayoutManager(linearLayoutManager);
        adapterExList = new Adapter_ExList(list);
        idExlistRecyclerview.setAdapter(adapterExList);
    }
    private void setList(){
        int L0=15;
        int L1=5;
        for (int i = 0; i < L0; i++) {
            Level0Item level0Items=new Level0Item("级别0__"+i+"条目",false);
            for (int i1 = 0; i1 < L1; i1++) {
                Level1Item level1Item=new Level1Item("级别1__"+i+"条目",false);
                level0Items.addSubItem(level1Item);
            }
            list.add(level0Items);
        }

        adapterExList.notifyDataSetChanged();
    }
    private void setAdapterExList(){
        adapterExList.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (adapter.getItemViewType(position)){
                    case 0:
                        List<Level0Item> list=  adapter.getData();
                        if (list.get(position).isExpanded()){
                            adapter.collapse(position);
                        }else {
                            adapter.expand(position);
                        }
                        Toast.makeText(ExListActivity.this, ""+position, Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(ExListActivity.this, ""+position, Toast.LENGTH_SHORT).show();
                        break;
                }

            }
        });
    }
}
